#Include ScrollGui.ahk

Esc:: ExitApp()

; ========== sample 1
; 演示常规使用
parent := Gui('+Resize')
parent.BackColor := 'f1ffb1'
parent.AddText('x0 y0', 'Sample')

child := Gui()
Loop 100 { ; 添加一些控件
  i := A_Index
  Loop 5 {
    If A_Index = 1
      child.AddText('xm y+10 w21 h21 0x201', i)
    Else
      child.AddText('xm y+10 w21 h21 yp 0x201', i)
    child.AddEdit(' x+10 yp w55 hp r1', A_Index)
  }
}

; 注意：width 和 height 参数超过 child 的宽高则无效，以最大为准
; 所以，可能需要像下面一样添加占位
; e.g.
; child.AddText('w300 h400 x0 y0')
SG1 := ScrollGUI(child.Hwnd, 0, 100, "-Caption -Resize", 2, 2)
SG1.SetLine(2, 31)
SG1.Show("ScrollGUI1 Title", "x0 y100 NA")
; 将窗口嵌入到 gui 中
SG1.container.Opt('+Parent' parent.Hwnd)
DllCall('SetParent', 'ptr', SG1.container.Hwnd, 'ptr', parent.Hwnd)
parent.Show('w300 h400')


; ========= sample 2
; 演示 AdjustToChild 方法的使用方法
g2 := Gui()
g2.AddButton('x0 y0 w80 h20', 'Change size').OnEvent('Click', fn)
Loop 10 {
  i := A_Index
  Loop 5 {
    If A_Index = 1
      g2.AddText('xm y+10 w22 0x201', i)
    Else
      g2.AddText('x+10 w22 yp 0x201', i)
    g2.AddEdit('x+10 yp w55 hp r1', A_Index)
  }
}
SG2 := ScrollGUI(g2.Hwnd, 330, 200, "Caption Resize", 3, 4)
SG2.Show("ScrollGUI2 Title", "x100 y500 NA")

fn(*) {
  SG2.container.Move(, , 30) ; 父容器尺寸变化时需要调用
  SG2.AdjustToChild()

  ; 同样，子 gui 添加了新控件时也到调用，不再演示
}

; ========== sample 3
; 演示手动发送消息
child1 := Gui()
child1.SetFont('s15')
child1.AddText('x0 y0 w200 h100')
Loop 60 {
  i := A_Index
  t := child1.AddText('x0 yp+20 h20 Border Backgroundc8ffcb', i)
}
child1.BackColor := 'e5ffee'

SG3 := ScrollGUI(child1.Hwnd, 200, 200, "-Caption -Resize", 2, 2)
SG3.SetLine(2, 20)
SG3.Show("ScrollGUI1 Title", "x500 y500 NA")

container := SG3.container


a:: {
  SG3.On_WM_Scroll(1, 0, 0x0115, container.Hwnd)
}

d:: {
  SG3.On_WM_Scroll(0, 0, 0x0115, container.Hwnd)
}

q:: {
  while SG3.PosV > 1
    SendMessage(0x0115, 2, 0, SG3.container)
}

e:: {
  while SG3.MaxV - SG3.PageV + 1 > SG3.PosV
    SendMessage(0x0115, 3, 0, SG3.container)
}

; 如果要隐藏滚动条，调用下面的方法
; WinSetRegion('0-0 w180 h200', container)
